package io.renren.modules.sys.web_api.controller;

import io.renren.modules.sys.back.service.BtJishuInfoService;
import io.renren.modules.sys.back.service.BtWendaInfoService;
import io.renren.modules.sys.web_api.service.FirstPageService;
import io.renren.modules.sys.web_api.service.JiShuPageService;
import io.renren.modules.sys.web_api.service.WendaPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("api/jishu")
public class WebJiShuController {
    @Autowired
    private JiShuPageService jiShuPageService;
    @Autowired
    private FirstPageService firstPageService;
    @Autowired
    private BtJishuInfoService btJishuInfoService;

    @RequestMapping("/first")
    public String CrawlerFirst(Map<String,Object> backdata){
        List<Map<String,Object>> fenlei = firstPageService.firstPageProFenLei();
        backdata.put("fenlei",fenlei);
        List<Map<String,Object>> wenda = jiShuPageService.getAllJiShu();
        backdata.put("wenda",wenda);
        return "webpage/jishu";
    }
    @RequestMapping("/detail/{id}")
    public String CrawlerFirst(@PathVariable("id") Long id,Map<String, Object> backdata){
        if(id<0){
            return "404";
        }
        if(btJishuInfoService.selectById(id)==null){
            return "404";
        }
        List<Map<String,Object>> fenlei = firstPageService.firstPageProFenLei();
        backdata.put("fenlei",fenlei);
        Map<String,Object> detailinfo = jiShuPageService.getJiShuDatailInfo(id);
        backdata.put("detailinfo",detailinfo);
        List<Map<String,Object>> wenda = jiShuPageService.getAllJiShu();
        backdata.put("wenda",wenda);
        return "webpage/producdetail";
    }
}
